package com.util;

import java.util.concurrent.*;

/**
 * @Author: hanll
 * @ClassName: ThreadConfigUtils
 * @Date: 2022-11-01 13:41
 * @Version: 1.0
 * @Description:
 */
public class ThreadConfigUtils {

    private ThreadPoolExecutor threadPoolExecutor;

    public void initThread(Runnable runnable) {
        threadPoolExecutor = new ThreadPoolExecutor(
                10,
                20,
                60,
                TimeUnit.SECONDS,
                new SynchronousQueue<Runnable>()
        );
        threadPoolExecutor.execute(runnable);
    }

    public void shutdown() {
        threadPoolExecutor.shutdown();
        System.out.println("线程消费完成，停止线程！");
    }
}
